package com.liu.wode.controller;

import com.liu.wode.mapper.OrderMapper;
import com.liu.wode.mapper.RoomsMapper;
import com.liu.wode.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class OrderController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RoomsMapper roomsMapper;
    @RequestMapping("/myOrder")
    public String queryEmpList(Model model){
        List<Order> orders = orderMapper.queryOrderList();
        model.addAttribute("orders",orders);
        return "order/Olist";
    }

    @GetMapping("/delorder/{id}")
    public String delOrder(@PathVariable("id") Integer id,Model model){
        Order order = orderMapper.queryOrderById(id);
        if(order.getCheckout()==null){
            orderMapper.delOrder(id);
            roomsMapper.addSum(order.getNumber());
            model.addAttribute("msg","退房成功");
        }else {
            model.addAttribute("msg","不可重复退房");
        }
        List<Order> orders = orderMapper.queryOrderList();
        model.addAttribute("orders",orders);
        return "order/Olist";
    }

}
